<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button alias="sysSignatureAdd" :butn-icon="'plus'" :butn-type="'primary'"
                                   :show-no-right="true" @click="edit()">{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-dropdown
                            v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
                            <a-button style="margin-left: 8px"> {{$ti18('rxList.moreBtn','更多')}}
                                <a-icon type="down"/>
                            </a-button>
                            <a-menu slot="overlay">
                                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0"
                                             alias="sysSignatureDelete" :butn-icon="'delete'" :butn-type="'danger'"
                                             :show-no-right="false" @click="delByIds(selectedRowKeys)">
                                    <a-icon type="delete"/>
                                    {{$ti18('rxList.delBtn','删除')}}
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
           </span>
                </div>
                <div slot="searchbar" btnalign="right" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="close">
                    <a-form layout="vertical">
                        <a-form-item :label="i18n('form.imageName','图片名称')">
                            <a-input :placeholder="i18n('form.name','请输入名称','input')" v-model="queryParam.Q_FILE_NAME__S_LK"/>
                        </a-form-item>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-system/system/core/sysSignature/query"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="id"
                    @selectChange="onSelectChange"
                >

                    <span slot="isDefault" slot-scope="{ text, record }">
                        <a-tag :color="text == 1 ? 'green' : 'red'">
                            <span>{{ text == 1 ? i18n('list.yes','是') : i18n('list.no','否') }}</span>
                        </a-tag>

                    </span>
                    <span slot="fileId" slot-scope="{ text, record }">

                        <img style="width: 100px;height: 32px;" preview="true" :src="getPath(record.fileId)">
                    </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                        <span @click="edit(record.id)">{{$ti18('rxList.editBtn','编辑')}}</span>
                        <span @click="delByIds([record.id])">{{$ti18('rxList.delBtn','删除')}}</span>
                    </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import SysSignatureApi from '@/api/system/core/sysSignature'
import SysSignatureEdit from './SysSignatureEdit'
import {BaseList, RxFit, RxGrid,Util,TokenUtil} from "@lowcode/jpaas-common-lib";
import userState from "@/assets/js/userState";

export default {
    name: 'SysSignatureList',
    mixins: [BaseList,userState],
    components: {
        RxFit
    },
    data() {
        return {
            columns: [
                {
                    title: this.$ti18('rxList.index','序号'),
                    type: 'indexColumn',
                    width: 30,
                    dataIndex: 'serial',
                    scopedSlots: {customRender: 'serial'}
                },
                {title: this.i18n('form.name','名称'), dataIndex: 'fileName', width: 240},
                {title: this.i18n('form.owner','所属人'), dataIndex: 'createByName', width: 120},
                {title: this.i18n('form.isDefault','默认'), dataIndex: 'isDefault', width: 60,scopedSlots: {customRender: 'isDefault'}},

                {title: this.i18n('form.signature','签名'), dataIndex: 'fileId', width: 120, scopedSlots: {customRender: 'fileId'}},
                {title:this.i18n('form.createTime','开始时间'), dataIndex: 'createTime', width: 100},
                {title: this.$ti18('rxList.action','操作'), width: 60, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ]
        }
    },
    created() {
        var params=  this.$route.meta.params;
        if(params){
            var isAdmin=JSON.parse(params).isAdmin;
            if(!isAdmin){
                this.queryParam["Q_CREATE_BY__S_EQ"]=this.user.userId;
            }else {

            }
        }else{
            this.queryParam["Q_CREATE_BY__S_EQ"]=this.user.userId;
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"SysSignature",key);
        },
        delById(ids) {
            return SysSignatureApi.del({ids: ids.join(',')});
        },
        getListByParams(parameter) {
            return SysSignatureApi.query(parameter)
        },
        edit(pkId) {
            let self=this;
            Util.open({
                component: SysSignatureEdit,
                curVm: this,
                widthHeight: ['800px', '600px'],
                title: pkId?self.$ti18('rxList.editBtn','编辑'):self.$ti18('rxList.add','新增')+'-'+this.i18n('form.signature','签名'),
                data: {
                    pkId:pkId
                }
            }, function (action, data) {
                if (action != 'ok') {
                    return;
                }
                self.$refs.table.loadData();
            });
        },
        getPath(fileId) {
            if (fileId) {
                var accessToken = TokenUtil.getToken();
                fileId=Util.encryptWord(fileId);
                var url = '/api/api-system/system/core/sysFile/previewFile?fileId=' + fileId+"&accessToken="+ accessToken;
                return url;
            }
            return "";
        },
    }
}
</script>
<style scoped>
.table-operator {
    padding: 4px;
}

.table-operator button {
    margin: 2px;
}
</style>

